//
//  AppDelegate.m
//  TotalDemo
//
//  Created by gujian on 16/2/14.
//  Copyright © 2016年 gujian. All rights reserved.
//

#import "AppDelegate.h"
#import "GQJAnalyze.h"
#import "ViewController.h"
#import "ViewController1.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
{
    GQJAnalyze *_gqjAnalyze;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.rootViewController = [self getTabbar];
    
    [self setNavigaionBarAppearance];
    
    [self.window makeKeyAndVisible];
    
    _gqjAnalyze = [[GQJAnalyze alloc] init];
    [_gqjAnalyze enable];
    
//    [self testIDAndInstanceType];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"kGQJNotification" object:nil];
    
    
    return YES;
}


/**
 *  探索通知同步异步问题
 *
 *  @param noti 接到的notification
 */
- (void)handleNotification:(NSNotification *)noti
{
    LotLog(@"3currentThread%@-noti:%@", [NSThread currentThread], noti);
}


//测试id和instanceType的区别
//id是运行时确定具体的类型，而instanceType则是编译时确定
- (void)testIDAndInstanceType
{
    [[[[ViewController alloc] init] medthodA] methodx];
//        [[[[ViewController alloc] init] methodB] methodx];
    [[ViewController medhodC] methodx];
}

- (void)setNavigaionBarAppearance
{
    if (IS_IOS7_OR_LATER) {
        [[UINavigationBar appearance] setBarTintColor:COLOR_NAVIGATIONBAR];
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    }else
    {
        [[UINavigationBar appearance] setTintColor:COLOR_NAVIGATIONBAR];
    }
}

- (UITabBarController *)getTabbar
{
    
    ViewController *homeViewController = [[ViewController alloc] init];
    homeViewController.tabBarItem.title = @"主页";
    homeViewController.tabBarItem.image = [UIImage imageNamed:@"sun"];
    [homeViewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UICOLOR_ARGB(0xff666666)} forState:UIControlStateNormal];
    [homeViewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:UICOLOR_ARGB(0xffff3d4e)} forState:UIControlStateSelected];
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeViewController];
    homeNav.navigationBar.translucent = NO;
   
    UITabBarController *rootTabBarController = [[UITabBarController alloc] init];
    rootTabBarController.viewControllers = @[homeNav];
    [rootTabBarController.tabBar setTintColor:COLOR_THEME];
    
    return rootTabBarController;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
{
    if ([url.scheme isEqualToString:@"TotalDemo"]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"收到信消息" delegate:self
                                                  cancelButtonTitle:@"关闭" otherButtonTitles:@"去查看", nil];
        [alertView show];
    }
    
    return NO;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
